<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	
	String type = (String)request.getAttribute("type");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>会员消费</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		var type = "<%=type%>";
		var flag = true;
		var flag1 = true;
		
		function save(){
			if($('#fm').form('validate') && flag && flag1){
				var url =  path;
				url +=  "/consumerInfo/save.do?t="+new Date().getTime();
				url += "&type="+type;
				

				var data = "&userCardIdOrMobile="+escape(escape($('#userCardIdOrMobile').val()));
				data += "&amount="+escape(escape($('#amount').val()));
				data += "&score="+escape(escape($('#score').val()));
				
				$.ajax({
				  url: url,
				  data:data,
				  success: function(data) {
					   if(data == "1"){
						   window.location = path+"/consumerInfo/consumerInfoMgr.do";
					   }else{
						   alertBox("操作失败！");
					   }
				  }
				});
				
			}
		}
		
		function autoSetScore(){
			$('#score').numberbox('setValue',$('#amount').val());
			if(${sscore} < $('#score').val()){
				flag = false;
				document.getElementById("scoreCheckInfo").innerHTML = '商家可用积分余额不足！';
			}else{
				flag = true;
				document.getElementById("scoreCheckInfo").innerHTML = '';
			}
		}
		
		function callback(){
			window.location = path+"/consumerInfo/consumerInfoMgr.do";
		}
		
		function checkUserCardIdOrMobile(){
			$.ajax({
				url:path + "/consumerInfo/checkUserCardIdOrMobileExists.do?userCardIdOrMobile="+$('#userCardIdOrMobile').val(),
				success: function(data) {
					if(data == "1"){
						flag = false;
						document.getElementById("userCardIdOrMobileCheckInfo").innerHTML = '卡号或手机号无效！';
					}else{
						flag = true;
						document.getElementById("userCardIdOrMobileCheckInfo").innerHTML = '';
					}
				}
			});
		}
	</script>
  </head>
  
  <body>
   <div class="right">
	<h1><b>会员消费</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
	<form id="fm">
	<div class="ri_main">
		<table width="97%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
			<tr>
			    <td width="21%" align="left" bgcolor="#FFFFFF">商家可用余额：</td>
				<td width="79%" align="left" bgcolor="#FFFFFF">${sscore}(积分)</td>
			</tr>
			<tr>
				<td align="left" bgcolor="#FFFFFF">会员卡号/手机号：</td>
				<td align="left" bgcolor="#FFFFFF">
					<input onblur="checkUserCardIdOrMobile()" id="userCardIdOrMobile" class="easyui-numberbox" required="true" style="width:200px;"/> *
					<font id="userCardIdOrMobileCheckInfo" style="color: red;"></font>
				</td>
			</tr>
			<tr>
				<td align="left" bgcolor="#FFFFFF">消费金额：</td>
			    <td bgcolor="#FFFFFF">
					<input id="amount" class="easyui-numberbox" onblur="autoSetScore()" precision="2" required="true" style="width:200px;"/> *
			    </td>
			</tr>
			<tr>
				<td align="left" bgcolor="#FFFFFF">会员将获得积分：</td>
			    <td bgcolor="#FFFFFF">
					<input id="score" name="score" class="easyui-numberbox" disabled="disabled" precision="2" required="true" style="width:200px;">
					<font id="scoreCheckInfo" style="color: red;"></font>
			    </td>
			</tr>
		   
			<tr>
				<td align="center" bgcolor="#FFFFFF" colspan="2">
					<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">确认</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-undo" onclick="callback()">取消</a>
				</td>
			</tr>
		</table>
	</div>
	</form>
	</div>
  </body>
</html>
